<?php

class Admin_CustomerController extends Zend_Controller_Action
{

    public function init()
    {
        $this->_helper->layout->setLayout('admin/admin');

    }

    public function indexAction(){
        $params['page'] = $this->_getParam('page', 1);
        $params['limit'] = 5;
        $cache = Core_Global::getCache();
        $pages = ceil(count($cache->get('Customer:ListIds')) / $params['limit']);
        $params['start'] = $params['page']*$params['limit'] - $params['limit'];
        $params['end'] = $params['start'] + $params['limit'];
        if($params['end']>count($cache->get('RealCategory:ListIds'))){
            $end = count($cache->get('RealCategory:ListIds'));
        }
        $saleCategories = Model_Customer::getAll($params);

        $this->view->assign('pages', $pages);
        $this->view->assign('Customers', $saleCategories);

    }

    public function createAction()
    {
        $post = $this->_request->getPost();
        if ($post) {
            $result = Model_Customer::create($post);
            $this->_helper->json($result);
        } else {
            $this->_helper->json(0);
        }

    }

    public function updateAction(){
        $post = $this->_request->getPost();

        if($post){
            $result = Model_Customer::update($post);
            $this->_helper->json($result);
        }

    }

    public function deleteAction(){
        $catId = $this->_getParam('id');
        $result = Model_Customer::delete($catId);

        $this->_helper->json($result);
    }


}